from drf_haystack.serializers import HaystackSerializer
from rest_framework import serializers
from goods.models import SKU
from goods.search_indexes import SKUIndex


class SKUSerializers(serializers.ModelSerializer):
    '''商品序列化器类'''

    class Meta:
        model = SKU
        fields = ('id', "name", 'price', 'default_image_url', 'comments')


class SKUIndexSerializer(HaystackSerializer):
    '''搜索结果序列化器类'''
    object = SKUSerializers(label='商品')

    class Meta:
        index_classes = [SKUIndex]
        fields = ('text', 'object')
